﻿using System;
using System.Data;
using Token.Piker.BLL;
using System.Web.UI.WebControls;
using Token.Piker.Core;

namespace Token.Piker.Web
{
    public partial class Activity : PikerBasePage
    {
        static ActivityBLL activityMethod = new ActivityBLL();
        static PhotoBLL photoMethod = new PhotoBLL();

        protected void Page_Load(object sender, EventArgs e)
        {
            //对画题上面部分进行数据绑定
            rptSlide.DataSource = activityMethod.GetActivityList(3,"","ID desc");
            rptSlide.DataBind();
            //对全部画题进行绑定
            rptAll.DataSource = activityMethod.GetActivityList(4,"","ID desc");
            rptAll.DataBind();
            //对线上画题进行绑定
            rptOnline.DataSource = activityMethod.GetActivityList(4,"a.Flag=0","ID desc");
            rptOnline.DataBind();
            //对线下画题进行绑定
            rptOffline.DataSource = activityMethod.GetActivityList(4,"a.Flag=1","ID desc");
            rptOffline.DataBind();
        }

        /// <summary>
        /// 对rptAll进行嵌套绑定
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void rptAll_ItemDataBound(object sender, System.Web.UI.WebControls.RepeaterItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
            {
                //对图片进行绑定
                DataRowView drv = (DataRowView)e.Item.DataItem;
                int albumID = Convert.ToInt32(drv["AlbumID"].ToString());
                Repeater rep = (Repeater)e.Item.FindControl("rptAllImg");
                rep.DataSource = photoMethod.GetList(5, "Album="+albumID+"", "ID desc");
                rep.DataBind();
                Label lblPhotoCount = (Label)e.Item.FindControl("lblPhotoCountOne");
                lblPhotoCount.Text = photoMethod.GetList("Album=" + albumID + "").Tables[0].Rows.Count.ToString();
            }
        }

        /// <summary>
        /// 对rptOffline进行嵌套绑定
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void rptOffline_ItemDataBound(object sender, System.Web.UI.WebControls.RepeaterItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
            {
                DataRowView drv = (DataRowView)e.Item.DataItem;
                int albumID = Convert.ToInt32(drv["AlbumID"].ToString());
                Repeater rep = e.Item.FindControl("rptOfflineImg") as Repeater;
                rep.DataSource = photoMethod.GetList(5,"Album="+albumID+"","ID desc");
                rep.DataBind();
                //绑定图片的张数
                Label lblPhotoCount = e.Item.FindControl("lblPhotoCountThree") as Label;
                lblPhotoCount.Text = photoMethod.GetList("Album=" + albumID + "").Tables[0].Rows.Count.ToString();
            }
        }

        /// <summary>
        /// 对rptOnline进行嵌套绑定
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void rptOnline_ItemDataBound(object sender, System.Web.UI.WebControls.RepeaterItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
            {
                DataRowView drv = (DataRowView)e.Item.DataItem;
                int albumID = Convert.ToInt32(drv["AlbumID"].ToString());
                Repeater rep = e.Item.FindControl("rptOnlineImg") as Repeater;
                rep.DataSource = photoMethod.GetList(5, "Album="+albumID+"", "ID desc");
                rep.DataBind();
                //绑定图片的张数
                Label lblPhotoCount = e.Item.FindControl("lblPhotoCountTwo") as Label;
                lblPhotoCount.Text = photoMethod.GetList("Album=" + albumID + "").Tables[0].Rows.Count.ToString();
            }
        }
    }
}